using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AXBC = Microsoft.Dynamics.BusinessConnectorNet;
using AXMD = Microsoft.Dynamics.Framework.Metadata.Ax;
using Proxy = Microsoft.Dynamics.Framework.BusinessConnector.Proxy;

namespace DynamicsAXPS
{
    [System.Management.Automation.Cmdlet("Invoke", "AXStaticMethod")]
    public class Invoke_AXStaticMethod : System.Management.Automation.PSCmdlet
    {
        [System.Management.Automation.Parameter(Position = 0, Mandatory = true)]
        public string Class;

        [System.Management.Automation.Parameter(Position = 1, Mandatory = true)]
        public string Method;

        [System.Management.Automation.Parameter(Position = 2, Mandatory = false)]
        public object[] Parameters;

        private static object[] emptyparams = new object[0];

        protected override void ProcessRecord()
        {
            if (this.Parameters == null)
            {
                this.Parameters = emptyparams;
            }
            var ax = new AXBC.Axapta();
            ax.Logon(null, null, null, null);
            var retval = ax.CallStaticClassMethod(this.Class, this.Method, this.Parameters);
            this.WriteObject(retval);
            ax.Logoff();
        }
    }
}
